package com.food.chronicles.controller;

import com.food.chronicles.service.DataSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/sync")
@Slf4j
public class DataSyncController {

    @Autowired
    private DataSyncService dataSyncService;

    /**
     * 手动触发食谱数据同步
     * @return 同步结果信息
     */
    @PostMapping("/recipes")
    public void syncRecipes() {
        try {
            // 记录开始时间
            long startTime = System.currentTimeMillis();
            
            // 调用同步服务
            dataSyncService.syncRecipesData();
            
            // 计算耗时
            long duration = System.currentTimeMillis() - startTime;
            log.info("同步食谱数据耗时：{}ms", duration);
            return ;
        } catch (Exception e) {
            // 记录异常日志
            log.error("食谱数据同步失败", e);
            return;
        }
    }

}